<?php

namespace app\admin\controller;

use app\admin\server\Menu;
use think\Controller;
use think\Request;
use think\Session;

class AdminBase extends Controller
{
    protected $uid;

    /**
     * 初始化操作
     * @access protected
     */
    protected function _initialize()
    {
        $this->checkPower();

        $this->assign('nav', Menu::getTitle(input('powerid')));
    }

    protected function checkPower()
    {
        $request = Request::instance();
        $user = Session::get('user', 'admin');
        $power = explode(',', $user['powerid']);
        $action = $request->controller() . '/' . $request->action();

        ($user['adid'] != 1) && !in_array($action, ['Admin/index', 'Index/index', 'Login/index', 'Login/logout', 'Node/icon']) && !Menu::checkPower($power, $action) && $this->error('你没有权限访问');
    }

}